package grape.attend.rest.user.mapper;

import grape.attend.service.user.po.UserLeave;
import grape.common.rest.mvc.WebMapper;
import org.mapstruct.Mapper;
import grape.attend.rest.user.form.UserLeaveCreateForm;
import grape.attend.rest.user.form.UserLeaveUpdateForm;
import grape.attend.rest.user.form.UserLeaveListPageForm;
import grape.attend.rest.user.vo.UserLeaveVo;
import org.mapstruct.ReportingPolicy;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户请假表 前端领域模型映射
 * </p>
 *
 * @author yangwei
 * @since 2020-05-18
 */
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserLeaveWebMapper extends WebMapper<UserLeaveVo, UserLeave> {

    UserLeave formToPo(UserLeaveCreateForm f);
    UserLeave formToPo(UserLeaveUpdateForm f);
    UserLeave formToPo(UserLeaveListPageForm f);

    default List<UserLeave> formsToPos(List<UserLeaveCreateForm> createForms) {
        if (createForms == null) {
            return null;
        }
        return createForms.stream().map(this::formToPo).collect(Collectors.toList());
    }
}
